<?php
/**
 * Created by IntelliJ IDEA.
 * User: m1573
 * Date: 2022/7/22
 * Time: 12:25
 */
    $category = $_GET["category"];
    $level = $_GET["level"];

    $answer = $_GET["answer"];
    $question = $_GET["question"];

    include("include/util.inc.php");

    $table = select_questions_like($category,$level,$answer,$question,$PDO);

    function format_table($table)
    {
        $html = "
                        <thead>
                      
                        <th class='col-lg-5'>
                            question
                        </th>
                        <th class='col-lg-1'>category</th>
                        <th class='col-lg-1'>level</th>
                        <th class='col-lg-2'>answer</th>
                        
                        
                        <th class='col-lg-1'>#</th>
                        </thead>";
        for ($i = 0; $i < count($table); $i = $i + 1) {
            $row = $table[$i];
            $html = $html . "<tr>
                        
                            <td class='question'>{$row["question_part"]}</td>
                           <td class='category'>{$row["category"]}</td>
                           <td class='level'>{$row["level_part"]}</td>
                           <td class='answer'>{$row["answer_part"]}</td>
                           
                           
                           <td><button class='btn btn-success' value='{$row["qid"]}' onclick='edit(this)'>edit</button></td>
                           <td><button class='btn btn-danger' value='{$row["qid"]}' onclick='delete_(this)'>delete</button></td>
                                    </tr>";

        }


        return $html;
    }
    echo format_table($table);
    ?>